<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascript">
var xmlhttp;
var gMessageId;
var gTimerId;
var gCounter;
function initXMLHttpClient() {
    
    try {
        // Mozilla / Safari / IE7
        xmlhttp = new XMLHttpRequest();
    } catch (e) {
         // IE
         var XMLHTTP_IDS = new Array('MSXML2.XMLHTTP.5.0',
                                    'MSXML2.XMLHTTP.4.0',
                                    'MSXML2.XMLHTTP.3.0',
                                    'MSXML2.XMLHTTP',
                                    'Microsoft.XMLHTTP' );
       var success = false;
         for (var i=0;i < XMLHTTP_IDS.length && !success; i++) {
             try {
                  xmlhttp = new ActiveXObject(XMLHTTP_IDS[i]);
                     success = true;
               } catch (e) {}
         }
         if (!success) {
             throw new Error('Unable to create XMLHttpRequest.');
         }
    }
    return xmlhttp;
}

function compareStr(pVal1, pVal2) {

	alert(pVal1.charAt(0));
	if(pVal1.value == pVal1.value) {
		log("They are equal");
		return true;
	}
	else {
		log("They are not equal");
		return false;
	}
}

function trim(s)
{
    var l=0; var r=s.length -1;
    while(l < s.length && s[l] == ' ')
    {     l++; }
    while(r > l && s[r] == ' ')
    {     r-=1;     }
    return s.substring(l, r+1);
} 

	function checkStatus() 	{

	  	//log("Timer fired now with " + gMessageId);
	  	gCounter = gCounter + 1;
	  	if(gCounter == 20)
	  	{
	  		clearTimeout(gTimerId);
	  		 document.getElementById('debug_msg').innerHTML = "<img src=\"icons/timeup.png\" alt=\"Passed Authentication\" />";
	  		return;
	  	}
	  	var url = "/AuthGetStatus";
	    var params = "id=" + gMessageId;
	
	    xmlhttp.open("POST",url,true);
	    xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	    xmlhttp.setRequestHeader("Content-length", params.length);
	    xmlhttp.setRequestHeader("Connection", "close");
	
	    xmlhttp.onreadystatechange = function()   {
			if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			     //log(xmlhttp.responseText);  
			     lStr = xmlhttp.responseText;
			     //alert(lStr.charAt(0));
			     if(lStr.charAt(0)== 'P' ) {
				     //alert("PASSED");
				     clearTimeout(gTimerId);
				     document.getElementById('debug_msg').innerHTML = "<img src=\"icons/passed.png\" alt=\"Passed Authentication\" />";
				     return;
			     }
			     if(lStr.charAt(0)== 'F' ) {
				     //alert("FAILED");
				     clearTimeout(gTimerId);
				     document.getElementById('debug_msg').innerHTML = "<img src=\"icons/failed.png\" alt=\"Time up Authentication\" />";
				     return;
			     }  
			     
				       
			} else {
			     //log("Failed to generate a response");    
			}
	    }
	    xmlhttp.send(params);
	    gTimerId = setTimeout("checkStatus()",5000);
    	return true;
	}

	function log(pMessage) {
		document.getElementById('debug_msg').innerHTML += pMessage + "<BR>";  
	}

  	function authTimer(pAuthMessageId) {
  	  gMessageId = pAuthMessageId;
  	  setTimeout("checkStatus()",1000); 	
	
  	}

    function initialize(pAuthMessageId) {
    	initXMLHttpClient();
    	//log("Got auth id as " + pAuthMessageId);
    	gCounter = 0;
    	document.getElementById('debug_msg').innerHTML = "<B>Authenticating .." +   "<img src=\"icons/processing.gif\" alt=\"Processing\" />";
     	authTimer(pAuthMessageId);
     	
    }

    function onBtnClick(pClickedId)
    {
     alert("Button clicked now " + pClickedId);
     var lRowImg = document.getElementById(pClickedId);
     alert(pClickedId + " the src = " + lRowImg.src + " Width : " + lRowImg.width + " Height : " + lRowImg.height);
	
      
    }
  
    </script>
  </head> 
  <body onload="initialize('<% out.print(request.getSession().getAttribute("id")); %>');">
   <!--   <% out.print(request.getSession().getAttribute("id")); %> -->
   <br></br><br></br><br></br>
    <center><div id="debug_msg" style="align:center;"></div></center> 
  </body>
</html>

